C++: Speed up Ssa::getAnUltimateDefinition - #22425
Open
MathiasVP wants to merge 5 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Optimizes C++ SSA ultimate-definition traversal by pruning searches to relevant definitions.
Changes:
- Adds a bounded, configurable ultimate-definition module.
- Applies it to flow summaries and iterator flow.
- Preserves the existing unrestricted API.
Show a summary per file
| File | Description |
|---|---|
SsaImpl.qll |
Adds optimized SSA traversal. |
DataFlowUtil.qll |
Exposes the new module. |
DataFlowPrivate.qll |
Optimizes iterator flow traversal. |
FlowSummaryImpl.qll |
Restricts traversal to callable definitions. |
Review details
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
- Files reviewed: 4/4 changed files
- Comments generated: 1
- Review effort level: Balanced
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
For a long time we've had an implementation of
Ssa::getAnUltimateDefinitionwhich is pretty much just a total copy/paste from the other languages, and the only use we've have for it has been when implementing iterator flow in SSA.However, in 150d0a7 we started using it in
FlowSummaryImpl.qllas well. And it turns out this predicate now performs poorly on a single DCA project (I guess maybe the predicate was magic'd prior to this change? I didn't actually check).I don't expect that there's anything wrong with the predicate, and it's probably more likely that this project just has some crazy pattern somewhere.
With that said, it's quite simple to speed up the uses we have by doing an initial pruning phase.
FlowSummaryImpl.qllis the simplest case since we have some ready bounds for one of th end-points (i.e., the ultimate definition).getAnUltimateDefinition. So for each iteration we have to provide a bound for the end-point, and that bound depends on the pruning we've done so far. This all leads to some fun recursion 🙈. I think it's all working well, though!Before:
After: